<?php

namespace App\http\Models;

use Illuminate\Database\Eloquent\Model;
use DB;
use Log;

class Smiles extends Model
{
    /**
     * 插入图片名
     * @return int
     */
    public function addUrl($insert_array)
    {
        try {
            $mc_id=DB::table('smiles')->insertGetId($insert_array);
        } catch (Exception $e) {
            Log::info($e->getMessage());
        }
        return $mc_id;
    }

    /**
     * 分页返回图片列表
     * @return mixed
     */
    public function getSmiles()
    {
        try {
            $smile_list=DB::table('smiles')->paginate(15);
        } catch (Exception $e) {
            Log::info($e->getMessage());
        }
        return $smile_list;
    }

    /**
     * 根据id获取表情包详情
     * @param $id
     * @return mixed
     */
    public function getSmileById($id)
    {
        try {
            $smile=DB::table('smiles')
                ->where('id','=',$id)
                ->first();
        } catch (Exception $e) {
            Log::info($e->getMessage());
        }
        return $smile;
    }

    /**
     * 根据id更新表情包
     * @param $id
     * @param $update_array
     * @return bool
     */
    public function updateSmileById($id,$update_array)
    {
        try {
            $bool = DB::table('smiles')
                ->where('id','=',$id )
                ->update($update_array);
            if(!$bool){
                return false;
            }
        } catch (Exception $e) {
            Log::info($e->getMessage());
        }
        return $bool;
    }
}